<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\mobilenode\model;

class CoachCashRecord extends \app\BaseModel
{
    protected $name = "massage_admin_update_coachcash_list";
    public function dataAdd($data)
    {
        $data["create_time"] = time();
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function orderResult($order_code, $transaction_id)
    {
        $order = $this->dataInfo(["order_code" => $order_code, "transaction_id" => ""]);
        if(!empty($order)) {
            \think\facade\Db::startTrans();
            $update = ["transaction_id" => $transaction_id, "pay_type" => 2, "pay_time" => time()];
            $res = $this->dataUpdate(["id" => $order["id"], "transaction_id" => ""], $update);
            if($res == 0) {
                \think\facade\Db::rollback();
                return false;
            }
            $admin_model = new \app\admin\model\Admin();
            $cash = $order["cash"];
            $admin_model->where(["id" => $order["admin_id"]])->update(["cash" => \think\facade\Db::Raw("cash+" . $cash)]);
            \think\facade\Db::commit();
        }
        return true;
    }
}

?>